﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

/*
"bedrijfsnaam","adres","postcode","plaats","type","status","website","rechtsvorm"
"By Jills","Pieter Molijnlaan 10","2343ES","Oegstgeest","Nevenvestiging","Vestiging is uitgeschreven uit het handelsregister",,
"Wining & Dining By Jills","Morsstraat 6","2312BM","Leiden","Hoofdvestiging",,,
*/

namespace MySQL.Db
{
	public class CsvParser
	{
		//
		//TODO: handle quote as part of the value. 
		//
		public static StringCollection ParseLine(string input)
		{
			bool inQuote = false;
			StringCollection values = new StringCollection();
			StringBuilder name = new StringBuilder();

			for (int i=0; i < input.Length; i++)
			{
				char c = input[i];

				if (c == '"')
				{
					inQuote = !inQuote;
					continue;
				}
				
				if (c != ',' && !inQuote)
					continue;

				if (c == ',' && !inQuote)
				{
					values.Add(name.ToString());
					name.Clear();
					continue;
				}

				name.Append(c);
			}

			values.Add(name.ToString());

			return values;
		}
	}
}
